package com.study.juc2;

import java.util.concurrent.CountDownLatch;

/**
 * @author study
 * @version 1.0
 * @date 2020/9/22 21:49
 */
public class CountDownLatchDemo {
    public static void main(String[] args) throws InterruptedException {

        //控制线程顺序
        CountDownLatch downLatch = new CountDownLatch(6);
        for (int i = 1; i <= 6; i++) {
            new Thread(() -> {
                System.out.println(Thread.currentThread().getName() + "\t离开教室");
                downLatch.countDown();
            }, String.valueOf(i)).start();
        }
        downLatch.await();
        System.out.println(Thread.currentThread().getName() + "\t班长走人关门");
    }

    private static void errDemo() {
        for (int i = 1; i <= 6; i++) {
            new Thread(() -> {
                System.out.println(Thread.currentThread().getName() + "离开教室");
            }, String.valueOf(i)).start();
        }

        System.out.println(Thread.currentThread().getName() + "\t班长走人关门");
    }
}
